
#ifndef __GAMEBITMAP_H__
#define __GAMEBITMAP_H__

#include "basetype.h"

#include <windows.h>

#include "3dDef.h"

#define MAX_COLORS_PALETTE  256

// bitmap defines
#define BITMAP_ID            0x4D42 // universal id for a bitmap
#define BITMAP_STATE_DEAD    0
#define BITMAP_STATE_ALIVE   1
#define BITMAP_STATE_DYING   2 
#define BITMAP_ATTR_LOADED   128

#define BITMAP_EXTRACT_MODE_CELL  0
#define BITMAP_EXTRACT_MODE_ABS   1


// container structure for bitmaps .BMP file
typedef struct BITMAP_FILE_TAG
{
	BITMAPFILEHEADER bitmapfileheader;  // this contains the bitmapfile header
	BITMAPINFOHEADER bitmapinfoheader;  // this is all the info including the palette
	PALETTEENTRY     palette[256];      // we will store the palette here
	uint8            *buffer;           // this is a pointer to the data

} BITMAP_FILE, *BITMAP_FILE_PTR;


// the simple bitmap image
typedef struct BITMAP_IMAGE_TYP
{
	int state;          // state of bitmap
	int attr;           // attributes of bitmap
	int x,y;            // position of bitmap
	int width, height;  // size of bitmap
	int num_bytes;      // total bytes of bitmap
	int bpp;            // bits per pixel
	uint8 *buffer;      // pixels of bitmap

} BITMAP_IMAGE, *BITMAP_IMAGE_PTR;

//
int Flip_Bitmap(UCHAR *image, int bytes_per_line, int height);
	
int Copy_Bitmap(BITMAP_IMAGE_PTR dest_bitmap, int dest_x, int dest_y, 
				BITMAP_IMAGE_PTR source_bitmap, int source_x, int source_y, 
				int width, int height);

int Scroll_Bitmap(BITMAP_IMAGE_PTR image, int dx, int dy);
//

class CBitMapFile
{
public:

	CBitMapFile()
	{
		memset(&m_bitmap, 0, sizeof(BITMAP_FILE));
	}

	int LoadBitMapFile(char *filename, int dd_pixel_format = DD_PIXEL_FORMAT565);

	virtual ~CBitMapFile()
	{
		UnloadBitmapFile();
	}

	BITMAP_FILE_PTR		GetBitMap()
	{
		return &m_bitmap;
	}

protected:
	int UnloadBitmapFile();

	BITMAP_FILE		m_bitmap;
};

class CBitMapImage
{
public:

	CBitMapImage()
	{
		memset(&m_image, 0, sizeof(BITMAP_IMAGE));
	}

	virtual ~CBitMapImage()
	{
		DestroyImage();
	}

	BITMAP_IMAGE_PTR GetImage()
	{
		return &m_image;
	}

	int CreateImage(int x, int y, int width, int height, int bpp = 8);

	int Load_Image_Bitmap(	CBitMapFile* pBitMapFile,
							int cx,int cy,			// cell or absolute pos. to scan image from
							int mode);				// if 0 then cx,cy is cell position, else 
													// cx,cy are absolute coords

	int Load_Image_Bitmap16(CBitMapFile* pBitMapFile,
							int cx,int cy,			// cell or absolute pos. to scan image from
							int mode);				// if 0 then cx,cy is cell position, else 
													// cx,cy are absolute coords

	int Draw_BitMap(uint8 *dest_buffer, int lpitch, int transparent);
	int Draw_BitMap16(uint8 *dest_buffer, int lpitch, int transparent);


	int DestroyImage();

protected:

	BITMAP_IMAGE		m_image;
};

#endif